﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PDX.ChangeTracking
{
    /// <summary>
    /// An <see cref="ISnapshotHandler"/> that forwards changes to the result of
    /// a <see cref="SnapshotHandlerLocator"/>.
    /// </summary>
    public class DelegatingSnapshotHandler : ISnapshotHandler
    {
        SnapshotHandlerLocator locator;

        /// <summary>
        /// Initializes a new instance of the <see cref="DelegatingSnapshotHandler"/> class.
        /// </summary>
        /// <param name="locator">The locator.</param>
        public DelegatingSnapshotHandler(SnapshotHandlerLocator locator)
        {
            this.locator = locator;
        }

        /// <summary>
        /// Records the specified change.
        /// </summary>
        /// <param name="change">The change.</param>
        public void Handle(Snapshot change)
        {
            var recorder = locator.Handler;
            if (recorder != null)
            {
                recorder.Handle(change);
            }
        }
    }
}
